//
//  MsgPanel.m
//  Dolphin
//
//  Created by Matthew on 11-10-27.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "MsgPanel.h"


@implementation MsgPanel

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) 
    {
        // Initialization code
        // Initialization code
        uiImageView =[[UIImageLayer alloc] initWithFrame:CGRectMake(0,0, frame.size.width, frame.size.height)];
        [uiImageView initImage:@"round_rect_bg.png" useOriginalSize:TRUE ratioMode:1 layerInfo:Nil]; 
        
        [self addSubview:uiImageView];
        
        infoTextfield = [[UITextField alloc] initWithFrame:CGRectMake(0, -3,frame.size.width, frame.size.height)];
        infoTextfield.textAlignment = UITextAlignmentCenter;
        infoTextfield.enabled = false;
        infoTextfield.borderStyle = UITextBorderStyleNone;//UITextBorderStyleRoundedRect;
        infoTextfield.textColor = [UIColor whiteColor]; //text color
        infoTextfield.font = [UIFont systemFontOfSize:17];  //font size
        infoTextfield.frame = CGRectMake(infoTextfield.frame.origin.x, 0.10*frame.size.height, 
                                         infoTextfield.frame.size.width,infoTextfield.frame.size.height);
        infoTextfield.backgroundColor =[UIColor clearColor];
        infoTextfield.autocorrectionType = UITextAutocorrectionTypeNo;	// no auto correction support    
        
        infoTextfield.text = @"";
        [self addSubview:infoTextfield];
        
        activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        activityIndicator.frame = CGRectMake(self.frame.size.width/2-20, self.frame.size.height/2-15, 40.0, 40.0);
        [activityIndicator startAnimating];
        [self addSubview:activityIndicator];
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

-(void) displayMsg:(NSString *) msg
{
    if (self.alpha>0) 
    {
        return;
    }
    
    self.alpha = 1.0f;
    
    infoTextfield.text = msg;
    
    [UIView animateWithDuration:1.0 delay:1.0f options:UIViewAnimationCurveEaseOut 
                     animations:^{self.alpha = 0.0f;} 
                     completion:Nil];
}

- (void)dealloc
{
    [super dealloc];
}

@end
